﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;

namespace YArchitech.Revit.MEP.Opening.Common
{
	internal class RevitTools
	{
		public static string GetLinkPath(List<string> listPath, string strKey)
		{
			foreach (string text in listPath)
			{
				if (text.Contains(strKey))
				{
					return text;
				}
			}
			return "";
		}

		public static List<string> GetLinkFilePaths(Autodesk.Revit.DB.Document doc)
		{
			List<string> list = new List<string>();
			foreach (ElementId id in ExternalFileUtils.GetAllExternalFileReferences(doc))
			{
				if (RevitVersionFuncs.GetElement(doc, id).IsExternalFileReference())
				{
					ExternalFileReference externalFileReference = RevitVersionFuncs.GetElement(doc, id).GetExternalFileReference();
					if (1 == (int)externalFileReference.ExternalFileReferenceType)
					{
						list.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(externalFileReference.GetAbsolutePath()));
					}
				}
			}
			return list;
		}

		public static double mmToFeet(double val)
		{
			return val / 304.8;
		}

		public static IntPtr GetIntPtr()
		{
			return Process.GetCurrentProcess().MainWindowHandle;
		}

		public static System.Windows.Forms.Form GetRevitForm()
		{
            return (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(RevitTools.GetIntPtr());
		}
	}
}
